/**
 * 聊呗工具类
 */
var LiaoBeUtil = {};
/**
 * 是否安装
 * @return {Boolean}
 * @public
 */
LiaoBeUtil.isInstalled = function () {
    if (cc.sys.os == cc.sys.OS_IOS) {
        return jsb.reflection.callStaticMethod('LiaoBeUtil', 'isInstalled');
    } else if (cc.sys.os == cc.sys.OS_ANDROID) {
        return jsb.reflection.callStaticMethod(packageUri + '/utils/LiaoBeUtil', 'isInstalled', '()Z');
    }
};
/**
 * 拉起登录
 * @public
 */
LiaoBeUtil.redirectLogin = function () {
    if (cc.sys.os == cc.sys.OS_IOS) {
        jsb.reflection.callStaticMethod('LiaoBeUtil', 'redirectLogin');
    } else if (cc.sys.os == cc.sys.OS_ANDROID) {
        jsb.reflection.callStaticMethod(packageUri + '/utils/LiaoBeUtil', 'redirectLogin', '()V');
    }
};
/**
 * 登录回调
 * @param {String} code
 * @public
 */
LiaoBeUtil.loginResq = function (code) {
    eventManager.dispatchEvent(EventKey.ReceiveLiaobeCode, code);
};
/**
 * 分享回调
 * @param code
 * @public
 */
LiaoBeUtil.shareResq = function (code) {
    eventManager.dispatchEvent(EventKey.ReceiveLiaobeShare, code);
};
/**
 * 分享网址
 * @param {String} url
 * @param {String} title
 * @param {String} description
 * @public
 */
LiaoBeUtil.shareUrl = function (url, title, description) {
    if (cc.sys.os == cc.sys.OS_IOS) {
        jsb.reflection.callStaticMethod(
            'LiaoBeUtil',
            'shareUrl:title:description:',
            url, title, description
        );
    } else if (cc.sys.os == cc.sys.OS_ANDROID) {
        jsb.reflection.callStaticMethod(
            packageUri + '/utils/LiaoBeUtil',
            'shareUrl', '(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V',
            url, title, description
        );
    }
};
/**
 * 分享网址
 * @param {String} url
 * @param {String} title
 * @param {String} description
 * @param {String} path
 * @public
 */
LiaoBeUtil.shareUrlWithIcon = function (url, title, description, path) {
    if (cc.sys.os == cc.sys.OS_IOS) {
        jsb.reflection.callStaticMethod(
            'LiaoBeUtil',
            'shareUrlWithIcon:title:description:path:',
            url, title, description, path
        );
    } else if (cc.sys.os == cc.sys.OS_ANDROID) {
        jsb.reflection.callStaticMethod(
            packageUri + '/utils/LiaoBeUtil',
            'shareUrlWithIcon', '(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V',
            url, title, description, path
        );
    }
};
/**
 * 分享图片
 * @param {String} path
 * @public
 */
LiaoBeUtil.sharePic = function (path) {
    if (cc.sys.os == cc.sys.OS_IOS) {
        jsb.reflection.callStaticMethod(
            'LiaoBeUtil',
            'sharePic:',
            path
        );
    } else if (cc.sys.os == cc.sys.OS_ANDROID) {
        jsb.reflection.callStaticMethod(
            packageUri + '/utils/LiaoBeUtil',
            'sharePic', '(Ljava/lang/String;)V',
            path
        );
    }
};
/**
 * 截图
 * @param {cc.Node} node
 * @public
 */
LiaoBeUtil.shareCapture = function (node) {
    captureNode(node, function (path) {
        LiaoBeUtil.sharePic(path);
    });
};
/**
 * 分享文本
 * @param {String} text
 */
LiaoBeUtil.shareText = function (text) {
    if (cc.sys.os == cc.sys.OS_IOS) {
        jsb.reflection.callStaticMethod(
            'LiaoBeUtil',
            'shareText:',
            text
        );
    } else if (cc.sys.os == cc.sys.OS_ANDROID) {
        jsb.reflection.callStaticMethod(
            packageUri + '/utils/LiaoBeUtil',
            'shareText', '(Ljava/lang/String;)V',
            text
        );
    }
};
/**
 * 关联聊呗群
 * @param userId
 * @param userName
 * @param groupId
 * @param serverUrl
 */
LiaoBeUtil.associatedGroup = function (userId, userName, groupId, serverUrl) {
    if (serverUrl == undefined) {
        serverUrl = app.clubLiaoBeiGroupUrl + '?token=' + encodeURIComponent(gameData.lbToken) +
            '&openId=' + encodeURIComponent(gameData.lbOpenid) +
            '&area=' + app.clubArea + '&club_id=' + groupId + '&uid=' + userId;
    }
    if (cc.sys.os == cc.sys.OS_IOS) {
        jsb.reflection.callStaticMethod(
            'LiaoBeUtil',
            'associatedGroup:userName:groupId:serverUrl:',
            userId.toString(), userName.toString(), groupId.toString(), serverUrl.toString()
        );
    } else if (cc.sys.os == cc.sys.OS_ANDROID) {
        jsb.reflection.callStaticMethod(
            packageUri + '/utils/LiaoBeUtil',
            'associatedGroup', '(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V',
            userId.toString(), userName.toString(), groupId.toString(), serverUrl.toString()
        );
    }
};

/**
 * 加入聊呗群
 */
LiaoBeUtil.handlerJoinGroup = function (url) {
    if (cc.sys.os == cc.sys.OS_IOS) {
        jsb.reflection.callStaticMethod('LiaoBeUtil', 'handlerJoinGroup:', url.toString());
    } else if (cc.sys.os == cc.sys.OS_ANDROID) {
        jsb.reflection.callStaticMethod(packageUri + '/utils/LiaoBeUtil', 'handlerJoinGroup', '(Ljava/lang/String;)V', url.toString());
    }
};


